<?php
namespace app\admin\controller;
//导入Controller
use think\Controller;
//导入Db
use think\Db;
class Order extends Allow
{
    public function getindex(){
        $request=request();
        //获取需要修改的值
        $oname=$request->param('keywords');
        //获取订单信息 
        $order=Db::table('order')->where('oname','like',"%".$oname."%")->paginate(5);
        return $this->fetch("Order/index",['order'=>$order,'request'=>$request->param()]);
    }

    //订单详情
    public function getorder_info(){
        $request=request();
        //获取订单id
        $order_id=$request->param('id');
        $order_info=Db::table('order_info')->where('order_id',"{$order_id}")->select();
        return $this->fetch("Order/order_info",['order_info'=>$order_info]);
    }

    //修改订单状态
    public function getstatus(){
        $request=request();
        //获取订单id
        $id=$request->param('id');
        //获取需要修改状态的值
        $statu=$request->only('status');
        if(Db::table('order')->where('id',"{$id}")->update($statu)){
            $this->redirect("/adminorder/index");
        }
    }

    //删除订单
    public function getdel(){
        $request=request();
        //获取订单id
        $id=$request->param('id');
        //执行删除
        if(Db::table('order')->where('id',"{$id}")->delete()){
            Db::table('order_info')->where('order_id',"{$id}")->delete();
            $this->success("删除订单成功","/adminorder/index");
        }else{
            $this->error("删除订单失败","/adminorder/index");
        }

    }
}
